package com.fs.entity;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@EntityListeners(AuditingEntityListener.class)
@NamedEntityGraph(name="not_fetch_room_and_customer")
public class PurchaseRecord {

    @Id()
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Integer id;

    @ManyToOne
    protected Room room;

    @ManyToOne
    protected Customer customer;

    @ManyToMany
    protected Set<Friend> friends = new HashSet<>();

    protected Float amount;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    protected PurchaseState state;

    //用户在支付过程中锁定房间的时间段, 在其他用户支付时校验是否和此房间的时间段冲突
    protected Boolean payingLock = false;

    //自己生成的订单号
    protected String tradeNo;

    //微信支付订单号
    protected String wxTradeID;

    //支付时间
    protected LocalDateTime payTime;

    protected LocalDateTime beginTime;
    protected LocalDateTime endTime;

    @CreatedDate
    protected LocalDateTime createTime;

    @LastModifiedDate
    protected LocalDateTime updateTime;

    public void setRoom(Room room) {
        this.room = room;
    }

    public PurchaseState getState() {
        return state;
    }

    public void setState(PurchaseState state) {
        this.state = state;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public void setAmount(Float amount) {
        this.amount = amount;
    }

    public void setBeginTime(LocalDateTime beginTime) {
        this.beginTime = beginTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public Integer getId() {
        return id;
    }

    public Room getRoom() {
        return room;
    }



    public String getTradeNo() {
        return tradeNo;
    }

    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    public String getWxTradeID() {
        return wxTradeID;
    }

    public void setWxTradeID(String wxTradeID) {
        this.wxTradeID = wxTradeID;
    }


    public LocalDateTime getPayTime() {
        return payTime;
    }

    public void setPayTime(LocalDateTime payTime) {
        this.payTime = payTime;
    }

    public Boolean getPayingLock() {
        return payingLock;
    }

    public void setPayingLock(Boolean payingLock) {
        this.payingLock = payingLock;
    }

    public Customer getCustomer() {
        return customer;
    }

    public Set<Friend> getFriends() {
        return friends;
    }

    public Float getAmount() {
        return amount;
    }

    public LocalDateTime getBeginTime() {
        return beginTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public LocalDateTime getCreateDate() {
        return createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }
}
